﻿package mortal.game.manager.msgTip
{
    import com.greensock.*;
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.font.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;

    public class MsgSceneInfoImpl extends Sprite
    {
        private var _sceneInfoCache:Dictionary;
        private var _bmp:Bitmap;
        private var _titleTxt:TextField;
        private var _desTxts:Dictionary;
        private var _infoTxtFormat:TextFormat;
        private var _inTween:TweenMax;
        private var _outTween:TweenMax;
        private var _timerKey:uint;

        public function MsgSceneInfoImpl()
        {
            this._sceneInfoCache = new Dictionary();
            this._bmp = new Bitmap();
            this._desTxts = new Dictionary();
            this._infoTxtFormat = new GTextFormat(FontUtil.lishuName, 20, 16777215, false);
            this._infoTxtFormat.leading = 0;
            this._infoTxtFormat.align = TextFormatAlign.LEFT;
            mouseEnabled = false;
            mouseChildren = false;
            this._bmp.x = 270;
            this._bmp.y = 150;
            return;
        }// end function

        public function showMsg(param1:String, param2:Array) : void
        {
            this.hideMsg();
            if (!this._sceneInfoCache[param1])
            {
                this.createSceneCache(param1, param2);
            }
            this._bmp.bitmapData = this._sceneInfoCache[param1];
            this._bmp.alpha = 0;
            LayerManager.highestLayer.addChild(this._bmp);
            this.stageReseze();
            this._inTween = TweenMax.to(this._bmp, 3, {alpha:1, onComplete:this.onInEnd});
            return;
        }// end function

        private function createSceneCache(param1:String, param2:Array) : void
        {
            var _loc_3:int = 0;
            var _loc_5:String = null;
            var _loc_6:TextField = null;
            if (!this._titleTxt)
            {
                this._titleTxt = this.createTitleTxt();
                addChild(this._titleTxt);
            }
            this._titleTxt.text = param1;
            var _loc_4:* = param2.length;
            while (_loc_3 < _loc_4)
            {
                
                _loc_5 = param2[_loc_3];
                _loc_6 = this._desTxts[_loc_3];
                if (!_loc_6)
                {
                    _loc_6 = this.createInfoTxt(_loc_3);
                    this._desTxts[_loc_3] = _loc_6;
                }
                _loc_6.text = _loc_5;
                addChild(_loc_6);
                _loc_3++;
            }
            alpha = 1;
            filters = [FilterConst.nameGlowFilter, FilterConst.sceneDesFilter];
            var _loc_7:* = new BitmapData(this.width, this.height, true, 0);
            _loc_7.draw(this);
            this._sceneInfoCache[param1] = _loc_7;
            return;
        }// end function

        private function createInfoTxt(param1:int) : TextField
        {
            var _loc_2:TextField = null;
            _loc_2 = new TextField();
            _loc_2.defaultTextFormat = this._infoTxtFormat;
            _loc_2.width = 28;
            _loc_2.autoSize = TextFieldAutoSize.LEFT;
            _loc_2.multiline = true;
            _loc_2.wordWrap = true;
            _loc_2.mouseEnabled = false;
            _loc_2.x = 35 + param1 * _loc_2.width;
            _loc_2.y = 30;
            return _loc_2;
        }// end function

        private function createTitleTxt() : TextField
        {
            var _loc_1:* = new TextField();
            var _loc_2:* = new GTextFormat(FontUtil.lishuName, 25, 16777215, false);
            _loc_2.leading = 0;
            _loc_2.align = TextFormatAlign.LEFT;
            _loc_1.defaultTextFormat = _loc_2;
            _loc_1.width = 32;
            _loc_1.autoSize = TextFieldAutoSize.LEFT;
            _loc_1.multiline = true;
            _loc_1.wordWrap = true;
            _loc_1.mouseEnabled = false;
            return _loc_1;
        }// end function

        private function onInEnd() : void
        {
            this._timerKey = setTimeout(this.onTimeOut, 3000);
            return;
        }// end function

        private function onTimeOut() : void
        {
            this._outTween = TweenMax.to(this._bmp, 3, {alpha:0, onComplete:this.onOutEnd});
            return;
        }// end function

        private function onOutEnd() : void
        {
            this.hideMsg();
            return;
        }// end function

        public function hideMsg() : void
        {
            var _loc_2:TextField = null;
            clearTimeout(this._timerKey);
            if (this._inTween && this._inTween.active)
            {
                this._inTween.kill();
            }
            if (this._outTween && this._outTween.active)
            {
                this._outTween.kill();
            }
            if (this._bmp && this._bmp.parent != null)
            {
                this._bmp.parent.removeChild(this._bmp);
            }
            if (this._titleTxt)
            {
                this._titleTxt.text = "";
            }
            var _loc_1:int = 1;
            while (_loc_1 < numChildren)
            {
                
                _loc_2 = removeChildAt(_loc_1) as TextField;
                _loc_2.text = "";
            }
            return;
        }// end function

        public function stageReseze() : void
        {
            return;
        }// end function

        override public function get width() : Number
        {
            return 32 + (numChildren - 1) * 30;
        }// end function

        override public function get height() : Number
        {
            return 500;
        }// end function

    }
}
